home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 1127 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  5.1 KB

  1. Subject: Re: MInixfs crash ...  try this :)
  2. Date: Thu, 3 Mar 94 21:44:10 CET
  3. From: Juergen Lock <nox@jelal.north.de>
  4. In-Reply-To: <9402240057.AA00539@jelal.north.de>; from "Juergen Lock" at Feb 24, 94 1:57 am
  5. Message-Id: <9403032044.AA00193@jelal.north.de>
  6.  
  7. earlier i wrote...
  8.  
  9. >  hmm i had crashes in rsmtp (uucp mail unbatcher), apparently in minixfs
  10. > unlink()ing a tempfile... (looked so with fsck)  the funny thing was it
  11. > happened only when there was an expire (cnews-xt) running at the same time...
  12. > fixstk rsmtp cured it.  (68000, no multitos.)
  13. >  now how can one process affect anothers stack?  is this a kernel bug?
  14. > race condition?  i have never seen update crashing but maybe this is the
  15. > same reason...
  16.  
  17.  now i even had to repair a filesystem because of what looked like such
  18. a stack overwrite crash... :/  after that i looked around and patched a few
  19. things, try this:
  20.  
  21. Index: signal.c
  22. @@ -257,8 +257,8 @@
  23.      long oldstack, newstack;
  24.      long *stack;
  25.      CONTEXT *call, contexts[2];
  26. -#define oldsysctxt (contexts[0])
  27. -#define newcurrent (contexts[1])
  28. +#define newcurrent (contexts[0])
  29. +#define oldsysctxt (contexts[1])
  30.  
  31.      extern void sig_return();
  32.  
  33. @@ -346,12 +346,12 @@
  34.              }
  35.          }
  36.  
  37. -        ++curproc->nsigs;
  38. +        ++curproc->nsigs;
  39.          call = &curproc->ctxt[SYSCALL];
  40.  /*
  41. - * what we do is build two fake stack frames; the bottom one is
  42. + * what we do is build two fake stack frames; the top one is
  43.   * for a call to the user function, with (long)parameter being the
  44. - * signal number; the top one is for sig_return.
  45. + * signal number; the bottom one is for sig_return.
  46.   * When the user function returns, it returns to sig_return, which
  47.   * calls into the kernel to restore the context in prev_ctxt
  48.   * (thus putting us back here). We can then continue on our way.
  49. @@ -359,7 +359,7 @@
  50.  
  51.  /* set a new system stack, with a bit of buffer space */
  52.          oldstack = curproc->sysstack;
  53. -        newstack = ((long) ( (&newcurrent) - 2 )) - 12;
  54. +        newstack = ((long) &newcurrent) - 0x40 - 12;
  55.  
  56.          if (newstack < (long)curproc->stack + ISTKSIZE + 256) {
  57.              ALERT("stack overflow");
  58. @@ -369,11 +369,6 @@
  59.              FATAL("system stack not in proc structure");
  60.          }
  61.  
  62. -/* unwound_stack is set by p_sigreturn() */
  63. -        if (sig == 0 && unwound_stack)
  64. -            curproc->sysstack = unwound_stack;
  65. -        else
  66. -            curproc->sysstack = newstack;
  67.          oldsysctxt = *call;
  68.          stack = (long *)(call->sr & 0x2000 ? call->ssp :
  69.                  call->usp);
  70. @@ -402,10 +397,6 @@
  71.          call->pc = (long) curproc->sighandle[sig];
  72.          call->sfmt = call->fstate[0] = 0;    /* don't restart FPU communication */
  73.  
  74. -        ((long *)curproc->sysstack)[1] = FRAME_MAGIC;
  75. -        ((long *)curproc->sysstack)[2] = oldstack;
  76. -        ((long *)curproc->sysstack)[3] = sig;
  77. -
  78.          if (curproc->sigflags[sig] & SA_RESET) {
  79.              curproc->sighandle[sig] = SIG_DFL;
  80.              curproc->sigflags[sig] &= ~SA_RESET;
  81. @@ -421,6 +412,20 @@
  82.              newcurrent.regs[0] = CTXT_MAGIC;
  83.                  /* set D0 so next return is different */
  84.              assert(curproc->magic == CTXT_MAGIC);
  85. +
  86. +/* unwound_stack is set by p_sigreturn() */
  87. +            if (sig == 0 && unwound_stack)
  88. +                stack = (long *) unwound_stack;
  89. +            else
  90. +/* newstack points just below our current sp, much less than ISTKSIZE away
  91. + * so better set it up with interrupts off...  -nox */
  92. +                stack = (long *) newstack;
  93. +            spl7();
  94. +            curproc->sysstack = (long) stack;
  95. +            ++stack;
  96. +            *stack++ = FRAME_MAGIC;
  97. +            *stack++ = oldstack;
  98. +            *stack = sig;
  99.              leave_kernel();
  100.              restore_context(call);
  101.          }
  102. @@ -486,7 +491,7 @@
  103.      }
  104.      else {
  105.          valid_return = 0;
  106. -        oldctxt = ((CONTEXT *)(&frame[2])) + 2;
  107. +        oldctxt = (CONTEXT *) (((long)&frame[2]) + 0x40);
  108.          if (oldctxt->regs[0] != CTXT_MAGIC) {
  109.              FATAL("p_sigreturn: corrupted context");
  110.          }
  111. Index: dosmem.c
  112. @@ -644,6 +644,7 @@
  113.          /* we guarantee ourselves at least 2 timeslices to do an Mshrink */
  114.              assert(curproc->magic == CTXT_MAGIC);
  115.              fresh_slices(2);
  116. +            spl7();
  117.              leave_kernel();
  118.              change_context(&(curproc->ctxt[CURRENT]));
  119.          }
  120. Index: proc.c
  121. @@ -573,10 +573,11 @@
  122.      curproc->ctxt[CURRENT].regs[0] = 1;
  123.      curproc = p;
  124.      proc_clock = TIME_SLICE;    /* fresh time */
  125. +    assert(p->magic == CTXT_MAGIC);
  126. +    spl7();
  127.      if ((p->ctxt[CURRENT].sr & 0x2000) == 0) {    /* user mode? */
  128.          leave_kernel();
  129.      }
  130. -    assert(p->magic == CTXT_MAGIC);
  131.      change_context(&(p->ctxt[CURRENT]));
  132.      /* not reached */
  133.      return 0;
  134. Index: syscall.spp
  135. @@ -373,6 +373,7 @@
  136.      move.b    d0,(a0)            ; store the character
  137.      addq.w    #1,d1
  138.      move.w    d1,_bconbsiz
  139. +    ori.w    #$0700,sr        ; spl7()
  140.      jsr    _leave_kernel        ; restore vectors
  141.      moveq.l    #-1,d0            ; return character output OK
  142.      rte
  143. Index: intr.spp
  144. @@ -92,6 +92,7 @@
  145.      jsr    _build_context        ; build context
  146.      move.l    _curproc,a0
  147.      move.l    (a0),sp            ; use curproc->sysstack
  148. +    move.w    P_CTXT0+C_SR(a0),d7    ; get saved int level
  149.  %ifdef ONLY030
  150.      clr.w    -(sp)            ; not a system call
  151.  %else
  152. @@ -99,6 +100,11 @@
  153.  %endif
  154.      jsr    _enter_kernel        ; enter kernel
  155.      addq.w    #2,sp
  156. +    move.w    sr,d1
  157. +    eor.w    d1,d7
  158. +    and.w    #$700,d7
  159. +    eor.w    d7,d1
  160. +    move.w    d1,sr            ; vbl allowed again
  161.      jsr    _preempt        ; yield processor
  162.      ori.w    #$700,sr        ; spl7()
  163.      jsr    _leave_kernel        ; restore vectors
  164.  
  165.  cheers
  166.     Juergen
  167. -- 
  168. J"urgen Lock / nox@jelal.north.de / UUCP: ..!uunet!unido!uniol!jelal!nox
  169.                                 ...ohne Gewehr
  170. PGP public key fingerprint =  8A 18 58 54 03 7B FC 12  1F 8B 63 C7 19 27 CF DA 
  171.